﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace TomNet.Attributes
{
    /// <summary>
    /// 半角数字チェック
    /// </summary>
    public class NumberAttribute : BaseAttribute
    {
        public override string Error
        {
            get
            {
                if (base.Error != null)
                {
                    return base.Error;
                }
                return "半角数字項目";
            }

            set => base.Error = value;
        }
        public override bool Validate(object value)
        {
            var regex = new Regex(@"^[0-9]*$");
            return value == null || regex.Match(value.ToString()).Success;
        }
    }
}
